home *** CD-ROM | disk | FTP | other *** search
/ Java Primer Plus / Java Primer Plus (Waite Group Proess)(1996).iso / chapter8 / calcfuture.java < prev    next >
Text File  |  1995-12-31  |  496b  |  22 lines

  1. /* Calculate future value */
  2. class calcfuture {
  3.  
  4.    public static void main(String args[]) {
  5.  
  6.        System.out.println(calc_future(0.0F,0.08f,4));
  7.        }
  8.  
  9.   /* method doing the work */
  10.    public static float calc_future (float principal,float interest,int years) {
  11.  
  12.        if (principal == 0.0) return 0.0f;
  13.  
  14.        float the_answer = principal; 
  15.  
  16.        for (int y=0; y<years; ++y)
  17.          the_answer += the_answer * interest;
  18.  
  19.        return the_answer;
  20.        }
  21.      }
  22.